package com.ruoyi.web.controller.mall.goodsImages.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.controller.mall.goodsImages.domain.GoodsImages;
import com.ruoyi.web.controller.mall.goodsImages.service.IGoodsImagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品图片Controller
 * 
 * @author ruoyi
 * @date 2021-01-18
 */
@Controller
@RequestMapping("/mall/goodsImages")
public class GoodsImagesController extends BaseController
{
    private String prefix = "mall/goodsImages";

    @Autowired
    private IGoodsImagesService goodsImagesService;

//    @RequiresPermissions("mall:goodsImages:view")
    @GetMapping()
    public String goodsImages()
    {
        return prefix + "/goodsImages";
    }

    /**
     * 查询商品图片列表
     */
//    @RequiresPermissions("mall:goodsImages:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GoodsImages goodsImages)
    {
        startPage();
        List<GoodsImages> list = goodsImagesService.selectGoodsImagesList(goodsImages);
        return getDataTable(list);
    }

    /**
     * 导出商品图片列表
     */
//    @RequiresPermissions("mall:goodsImages:export")
    @Log(title = "商品图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GoodsImages goodsImages)
    {
        List<GoodsImages> list = goodsImagesService.selectGoodsImagesList(goodsImages);
        ExcelUtil<GoodsImages> util = new ExcelUtil<GoodsImages>(GoodsImages.class);
        return util.exportExcel(list, "goodsImages");
    }

    /**
     * 新增商品图片
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商品图片
     */
//    @RequiresPermissions("mall:goodsImages:add")
    @Log(title = "商品图片", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GoodsImages goodsImages)
    {
        return toAjax(goodsImagesService.insertGoodsImages(goodsImages));
    }

    /**
     * 修改商品图片
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        GoodsImages goodsImages = goodsImagesService.selectGoodsImagesById(id);
        mmap.put("goodsImages", goodsImages);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品图片
     */
//    @RequiresPermissions("mall:goodsImages:edit")
    @Log(title = "商品图片", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GoodsImages goodsImages)
    {
        return toAjax(goodsImagesService.updateGoodsImages(goodsImages));
    }

    /**
     * 删除商品图片
     */
//    @RequiresPermissions("mall:goodsImages:remove")
    @Log(title = "商品图片", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String[] ids)
    {
        return toAjax(goodsImagesService.deleteGoodsImagesByIds(ids));
    }
}
